package com.demo.deal_service.dao;

import com.demo.deal_service.model.entity.Deal;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface DealDao {
    public static final String TABLE_NAME = " deal ";
    public static final String SELECT_COLUMN = " id,merchant_name,merchant_address,deal_title,deal_price,discount," +
            "deal_type,image_url,publish_status,inventory_amount,vendibility_amount,start_time,end_time,publish_time," +
            "create_time,update_time,category,remark ";
    public static final String INSERT_COLUMN = " merchant_name,merchant_address,deal_title,deal_price,discount," +
            "deal_type,image_url,publish_status,inventory_amount,vendibility_amount,start_time,end_time,publish_time," +
            "create_time,update_time,category,remark ";
    public static final String INSERT_PARAMS = " #{merchantName},#{merchantAddress},#{dealTitle},#{dealPrice},#{discount}," +
            "#{dealType},#{imageUrl},#{publishStatus},#{inventoryAmount},#{vendibilityAmount},#{startTime},#{endTime},#{publishTime}," +
            "#{createTime},#{updateTime},#{category},#{remark} ";

    @Select(" SELECT * FROM deal")
    List<Deal> selectAll();

    /**
     * 获取下一个自增主键值
     * @return
     */
    Long selectNextKey();

    @Insert(" INSERT INTO " + TABLE_NAME +
            " ( " + INSERT_COLUMN + " ) " +
            " VALUES( " + INSERT_PARAMS + " ) ")
    int insertDeal(Deal deal);

    @Select(" SELECT " + SELECT_COLUMN +
            " FROM " + TABLE_NAME +
            " WHERE id = #{id}")
    Deal selectById(Long id);

    @Delete(" DELETE " +
            " FROM " + TABLE_NAME +
            " WHERE id = #{id}")
    int deleteById(Long id);


    int updateDealById(Deal deal);

    int updateDealForOrder(Map param);
}
